import {
    _getSymbolTypeList,
    _getSymbolList,
    _getUserSymbolList,
}
from '../axios/index'

// app 中触发请求文件

export default {
    data() {
        return {}
    },
    watch: {
        blastingWarehouse1() {
            var self = this;
            var _val = Number(this.blastingWarehouse1);
            var text = "";
            if (_val > 0) {
                self.$store.commit("setBlastingWarehouse", 0);
                if (self.$js.Socket)
                    self.$js.Socket.send( {
                            type: "respond",
                            token: localStorage.getItem("token")
                        }
                    );
                if (_val == 2) {
                    self.$store.dispatch("getCcDataList");
                    self.$store.dispatch("getUser");
                    self.$store.dispatch("getGdDataList");
                    text = "您有订单已成交";
                } else if (_val == 4) {
                    self.$store.dispatch("getGdDataList");
                    text = "您有挂单已过期";
                } else {
                    self.$store.dispatch("getUser");
                    self.$store.dispatch("getCcDataList");
                    self.$store.dispatch("getDdDataList");
                    text = "您有订单已爆仓";
                }
                self.$Notice.open({
                    title: "提示",
                    desc: text
                });
            } else {}

        }
    }
    ,
    computed: {
        //爆仓
        blastingWarehouse1() {
            return this.$store.state.blastingWarehouse;
        },
       

    },
    methods: {
        // 触发获取商品类别列表的请求
        async getSymbolTypeListAction() {
            const $store = this.$store;
            let res = await _getSymbolTypeList();
            if (res.data.code == 200) {
                $store.state.symbolTypeList = res.data.data;
                // 商品详情列表的请求
                this.getSymbolListAction();
            } else console.error(`获取商品列表类型接口状态${res.data.code}`)
        },
        // 触发获取商品详情列表的请求
        async getSymbolListAction() {
            const $store = this.$store;
            let res = await _getSymbolList();
            if (res.data.code == 200) {
                $store.state.symbolList = res.data.data;
                for (const iterator of $store.state['symbolTypeList']) {
                    //获取商品类型索引
                    $store.state.symbolObj[iterator.type_name] = null;
                }
                for (const iterator of $store.state['symbolList']) {
                    //为已有商品类型索引，存ru商品列表。
                    $store.state.symbolObj[iterator.type_name] !== undefined ?
                        $store.state.symbolObj[iterator.type_name] = iterator : '';
               
                }
               

            } else console.error(`获取商品详情列表接口状态${res.data.code}`)

        }
        
    },
    created() {
        if (localStorage.getItem('token')) {
            this.$store.dispatch("getUser");
        }
        this.getSymbolTypeListAction();//获取商品列表
        const $store = this.$store.state;
        if (localStorage.getItem('symbol')) {
            $store.traViewSymboId = localStorage.getItem('symbol');
        }
        if (localStorage.getItem('token') && !$store.token) {
            $store.token = localStorage.getItem('token');
        }
        this.$store.getters.countConf("service_img");//获取客服微信
    },
    mounted() {
        var self = this;
        var token = localStorage.getItem("token");
        if (token) {
            var dd = setInterval(() => {
                if (self.$js.Socket) {
                    clearInterval(dd);
                    self.$js.Socket.send({
                        type: 'login',
                        token
                    });
                }
            }, 100);
        }

    }

}